package way.server;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.SystemProperties;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import way.server.R;
import way.sql.JSONParser;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.Toast;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.BDNotifyListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.ItemizedOverlay;
import com.baidu.mapapi.map.LocationData;
import com.baidu.mapapi.map.MKMapViewListener;
import com.baidu.mapapi.map.MapController;
import com.baidu.mapapi.map.MapPoi;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MyLocationOverlay;
import com.baidu.mapapi.map.Overlay;
import com.baidu.mapapi.map.OverlayItem;
import com.baidu.platform.comapi.basestruct.GeoPoint;
import com.android.internal.telephony.*;
import android.telephony.CellLocation;
import android.telephony.PhoneStateListener;
import android.provider.Settings.Secure; 

public class LocationAllShow extends Activity {
	
	static MapView mMapView = null;
	
	private MapController mMapController = null;

	public MKMapViewListener mMapListener = null;
	FrameLayout mMapViewContainer = null;
	
	private ProgressDialog pDialog;
	JSONParser jsonParser = new JSONParser();
	// 定位相关
	LocationClient mLocClient;
	public MyLocationListenner myListener = new MyLocationListenner();
    public NotifyLister mNotifyer=null;
    private static final String TAG_MESSAGE = "message";
	Button testUpdateButton = null;
	
	EditText getPhoneText = null;
	MyLocationOverlay myLocationOverlay = null;
	int index =0;
	LocationData locData = null;
	
	
	
	//define the urls  
	//static String url_down="http://okoop.my.phpcloud.com/findus/down/down.php";
	//static String url_up="http://okoop.my.phpcloud.com/findus/up/up.php";
	static String sIp="192.168.1.100";
	//static String sIp="10.0.0.2";
	String sDNSName="okoop.vicp.cc";
	static String url_down="http://"+sIp+"/down/down.php";
	static String url_down_all_user="http://"+sIp+"/down/showall.php";
	static String url_up="http://"+sIp+"/up/up.php";
	static String url_checkusr="http://"+sIp+"/up/checkusr.php";
	
	
	// 存放overlayitem s
	public List<OverlayItem> mGeoList = new ArrayList<OverlayItem>();
	
	Handler mHandler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            Toast.makeText(LocationAllShow.this, "i am here", Toast.LENGTH_SHORT).show();
        };
    };
    public String sUsrLon="";
    public String sUsrLat="";
    public String sUsrTime="";
    String sUinfo=""; 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_locationoverlay);
      
        mMapView = (MapView)findViewById(R.id.bmapView);
        getPhoneText=(EditText)findViewById(R.id.phoneNum);//取到号码
        mMapController = mMapView.getController();
        
        initMapView();
        
        mLocClient = new LocationClient( this );
        //mLocClient.registerLocationListener( myListener );
        
        //位置提醒相关代码
        mNotifyer = new NotifyLister();
        mNotifyer.SetNotifyLocation(42.03249652949337,113.3129895882556,3000,"bd09ll");//4个参数代表要位置提醒的点的坐标，具体含义依次为：纬度，经度，距离范围，坐标系类型(gcj02,gps,bd09,bd09ll)
        mLocClient.registerNotify(mNotifyer);
        LocationClientOption option = new LocationClientOption();
        option.setPriority(LocationClientOption.NetWorkFirst);  //设置网络优先 
        option.setOpenGps(true);//打开gps
        option.setCoorType("bd09ll");     //设置坐标类型
        option.setScanSpan(5000); // //定时定位，每隔5秒钟定位一次
        mLocClient.setLocOption(option);
        
        TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        //String imsi = mTelephonyMgr.getSubscriberId();
        //String imei = mTelephonyMgr.getDeviceId();
        //String IMSI =android.os.SystemProperties.get(android.telephony.TelephonyProperties.PROPERTY_IMSI);


        String imei =((TelephonyManager)this.getSystemService(TELEPHONY_SERVICE)).getDeviceId();
        String imsi =((TelephonyManager)this.getSystemService(TELEPHONY_SERVICE)).getSubscriberId();

        //String IMEI =android.os.SystemProperties.get(android.telephony.TelephonyManager.p.telephony.TelephonyProperties.PROPERTY_IMEI)
        WifiManager wifi = (WifiManager)this.getSystemService(Context.WIFI_SERVICE); 
        WifiInfo info = wifi.getConnectionInfo(); 
        String wifiimei = info.getMacAddress();
        TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
        String phoneNumber = telephonyManager.getLine1Number();
        String android_id = Secure.getString(getBaseContext().getContentResolver(), Secure.ANDROID_ID);
        Log.i("IMSI:", imsi);
        Log.i("IMEI:", imei);//最好拿
        Log.i("phoneNumber:", phoneNumber);
        Log.i("android_id:", android_id);
        Log.i("wifiimei:", wifiimei);//最好拿
        sUinfo=imei+wifiimei;
        
        mLocClient.registerLocationListener(new BDLocationListener(){

    			@Override
    			public void onReceiveLocation(BDLocation location) {
    				// TODO Auto-generated method stub
    				 if (location == null) 
    	                    return ; 
    	                StringBuffer sb = new StringBuffer(256); 
    	                sb.append("time : "); 
    	                sb.append(location.getTime()); 
    	                
    	                sUsrTime=location.getTime();
    	                sb.append("\nerror code : "); 
    	                sb.append(location.getLocType()); 
    	                sb.append("\nlatitude : "); 
    	                sb.append(location.getLatitude()); 
    	                sb.append("\nlontitude : "); 
    	                sb.append(location.getLongitude()); 
    	                
    	                sUsrLon=Double.toString(location.getLatitude());//get the longitude
    	                sUsrLat=Double.toString(location.getLatitude());//get the latitude
    	                
    	                
    	                
    	                sb.append("\nradius : "); 
    	                sb.append(location.getRadius()); 
    	                if (location.getLocType() == BDLocation.TypeGpsLocation){ 
    	                    sb.append("\nspeed : "); 
    	                    sb.append(location.getSpeed()); 
    	                    sb.append("\nsatellite : "); 
    	                    sb.append(location.getSatelliteNumber()); 
    	                } else if (location.getLocType() == BDLocation.TypeNetWorkLocation){ 
    	                    sb.append("\naddr : "); 
    	                    sb.append(location.getAddrStr()); 
    	                } 
    	                sb.append("\nsdk version : "); 
    	                sb.append(mLocClient.getVersion()); 
    	                Log.v("bts:",sb.toString());
    	                //mTextView.setText(sb.toString()); 
    	                //定时报告经纬度

    	                Updata tt=new Updata();
    	                tt.execute(sUinfo,sUsrLon,sUsrLat,sUsrTime);
    	        	        //tt.execute();            
    	                getAllUserLocation();	
    			}

    			@Override
    			public void onReceivePoi(BDLocation location) {
    				// TODO Auto-generated method stub
    				//
    			}	
            });
         
        mLocClient.start();
        
        mMapView.getController().setZoom(14);
        mMapView.getController().enableClick(true);
        
        mMapView.displayZoomControls(true);
        mMapListener = new MKMapViewListener() {
			
			@Override
			public void onMapMoveFinish() {
				// TODO Auto-generated method stub
			}
			
			@Override
			public void onClickMapPoi(MapPoi mapPoiInfo) {
				// TODO Auto-generated method stub
				String title = "";
				if (mapPoiInfo != null){
					title = mapPoiInfo.strText;
					Toast.makeText(LocationAllShow.this,title,Toast.LENGTH_SHORT).show();
				}
			}
		};
		
		mMapView.regMapViewListener(ApplicationMain.getInstance().mBMapManager, mMapListener);
		myLocationOverlay = new MyLocationOverlay(mMapView);
		locData = new LocationData();
	    myLocationOverlay.setData(locData);
		mMapView.getOverlays().add(myLocationOverlay);
		myLocationOverlay.enableCompass();
		mMapView.refresh();
		
		
		
		testUpdateButton = (Button)findViewById(R.id.updateClientData);
		OnClickListener clickListener = new OnClickListener(){
				public void onClick(View v) {
					testUpdateClick();
				}
	        };
	    testUpdateButton.setOnClickListener(clickListener);
	    
	   
    }
   
    
    class Updata extends AsyncTask<String, String, String> {
		@Override
		protected String doInBackground(String... arg0) {
			// TODO Auto-generated method stub
			
			
			String sUsr=arg0[0];
			String sLon=arg0[1];
			String sLat=arg0[2];
			String sTime=arg0[3];
			//String sNote=arg0[3];
			Log.i("query result:", "ttts");
			if(this.bCheckUsrInfo(sUsr)==false){
				  List<NameValuePair> params = new ArrayList<NameValuePair>();
		          params.add(new BasicNameValuePair("username", sUsr));
		          params.add(new BasicNameValuePair("lon", sLon));
		          params.add(new BasicNameValuePair("lat", sLat));
		          params.add(new BasicNameValuePair("time", sTime));
		          params.add(new BasicNameValuePair("note", "ok"));
		          try{
		        	  // getting JSON Object
		              // Note that create product url accepts POST method
		         	   JSONObject json = JSONParser.makeHttpRequest(url_up,"POST", params);		
		         	   //String re_username = json.getString("username");
			   	   		//	String re_longitude = json.getString("lon");
			   	   		//	String re_latitude = json.getString("lat");
			   	   			
			   	   		//	Log.v("test:", "用戶名="+re_username);
			   	   		//	Log.v("test:", "經度="+re_longitude);
			   	   		//	Log.v("test:", "緯度="+re_latitude);
		   	   			
		   	            String message = json.getString(TAG_MESSAGE);
		   	            return message;
		            }catch(Exception e){
		                e.printStackTrace(); 
		                return "";          
		            }
		          
			}else{
				return "";  
			}
		}
		private boolean bCheckUsrInfo(String sUsr){
			
			Log.i("query result:", "adfasdf");
		   	HttpClient client = new DefaultHttpClient();
			StringBuilder builder = new StringBuilder();

			String ulrs=url_checkusr;
		    ulrs+="?username="+sUsr;
		    Log.i("query result:", ulrs);
			HttpGet myget = new HttpGet(ulrs);	
			
			try {
				
				HttpResponse response = client.execute(myget);
				BufferedReader reader = new BufferedReader(new InputStreamReader(
				response.getEntity().getContent()));
				for (String s = reader.readLine(); s != null; s = reader.readLine()) {
					builder.append(s);
				}
				//String ss=builder.toString();
				Log.i("query result:",builder.toString());
				JSONObject jsonObject = new JSONObject(builder.toString());
				int re_success = jsonObject.getInt("success");
				if(re_success==1)
				{
					Log.i("数据存在:","1");
					return true;
				}
				else
				{
					Log.i("没有数据:","0");
					return false;
				}
			}catch (Exception e) {
				Log.i("test:", "false");
				e.printStackTrace();
				return false;
			}
		}
    	
    }
    
    private boolean validate(){
    	
    	 String description = this.getPhoneText.getText().toString().trim();
         if (description.equals(""))
         {
             //findus.sql.DialogUtil.showDialog(this, "您还没有填写建议", false);
             return false;
         }
         return true;
    }
    
    public void initPos()
    {  
        /** 
         * 创建图标资源（用于显示在overlayItem所标记的位置） 
         */  
    	
    	
        Drawable marker = this.getResources().getDrawable(R.drawable.ic_launcher);  
        // 为maker定义位置和边界   
        marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight());  
  
    	  /** 
         * 创建自定义的ItemizedOverlay 
         */  
        MyItemizedOverlay overlay = new MyItemizedOverlay(marker, this);  
  
        /** 
         * 创建并添加第一个标记：柳峰的家乡（经度：87.493147 纬度：47.118440） 
         */  
        // 构造一个经纬度点   
        //GeoPoint point = new GeoPoint((int)(47.118440*1E6), (int)(87.493147*1E6));  
        // 创建标记（新疆福海县）   
        //OverlayItem overlayItem = new OverlayItem(point, "柳峰的家乡", "新疆福海县");  
        // 将标记添加到图层中（可添加多个OverlayItem）   
        //overlay.addItem(overlayItem);  
  
        /** 
         * 创建并添加第二个标记：美丽的乌伦古湖（经度：87.249693 纬度：47.276757） 
         */  
        //point = new GeoPoint((int)(47.276757*1E6),(int)(87.249693*1E6));  
        // 创建标记（乌伦古湖）   
        //overlayItem = new OverlayItem(point, "美丽的乌伦古湖", "乌伦古湖是中国十大淡水湖之一");  
        // 将标记添加到图层中（可添加多个OverlayItem）   
        //overlay.addItem(overlayItem);  
  
        /** 
         * 往地图上添加自定义的ItemizedOverlay 
         */  
        //List<Overlay> mapOverlays = mMapView.getOverlays();  
        //mapOverlays.add(overlay);
        //mMapView.getOverlays().clear();
        
        //getUserLocation();
        String phoneno = this.getPhoneText.getText().toString();
        String ulrs=url_down;
        ulrs+="?username="+phoneno;
        getinfo(ulrs);
        //
        GeoPoint point1 = new GeoPoint((int)(lat*1E6),(int)(lon*1E6));  
        OverlayItem overlayItem1 = new OverlayItem(point1, "深圳", "深圳");  
        // 将标记添加到图层中（可添加多个OverlayItem）   
        
        overlay.addItem(overlayItem1); 
        mMapView.getOverlays().clear();
        mMapView.getOverlays().add(overlay);
	    //mMapView.getOverlays().addAll(mapOverlays);
	    mMapView.refresh();
	    mMapView.getController().setCenter(point1);
	    
    }
   
    public void getAllUserLocation(){
    	
    	HttpClient client = new DefaultHttpClient();
		StringBuilder builder = new StringBuilder();
		
		String sphoneNo=getPhoneText.getText().toString();
		String ulrs=url_down_all_user;
		getinfo(url_down_all_user);
		/*
		HttpGet myget = new HttpGet(ulrs);	
		try {
			HttpResponse response = client.execute(myget);
			BufferedReader reader = new BufferedReader(new InputStreamReader(
			response.getEntity().getContent()));
			for (String s = reader.readLine(); s != null; s = reader.readLine()) {
				builder.append(s);
			}
			Log.v("test:", "all="+builder.toString());
			JSONObject jsonObject = new JSONObject(builder.toString());
			String re_username = jsonObject.getString("username");
			String re_longitude = jsonObject.getString("lon");
			String re_latitude = jsonObject.getString("lat");
			//setTitle("用户"+re_user_id);
			
			int re_success = jsonObject.getInt("success");
			if(re_success==1)
			{
				Log.i("数据存在:","1");
				//return true;
			}
			else
			{
				Log.i("没有数据:","0");
				//return false;
			}
			Log.v("test:", "用戶名="+re_username);
			Log.v("test:", "經度="+re_longitude);
			Log.v("test:", "緯度="+re_latitude);
		} catch (Exception e) {
			Log.v("test:", "false");
			e.printStackTrace();
		}
		*/
    	
    }
    public void getUserLocation(String sUserInfo){
    	
    	HttpClient client = new DefaultHttpClient();
		StringBuilder builder = new StringBuilder();
		
		String sphoneNo=getPhoneText.getText().toString();
		String ulrs=url_down;
	    ulrs+="?username="+sphoneNo;
		HttpGet myget = new HttpGet(ulrs);	
		try {
			HttpResponse response = client.execute(myget);
			BufferedReader reader = new BufferedReader(new InputStreamReader(
			response.getEntity().getContent()));
			for (String s = reader.readLine(); s != null; s = reader.readLine()) {
				builder.append(s);
			}
			Log.v("test:", "all="+builder.toString());
			JSONObject jsonObject = new JSONObject(builder.toString());
			String re_username = jsonObject.getString("username");
			String re_longitude = jsonObject.getString("lon");
			String re_latitude = jsonObject.getString("lat");
			//setTitle("用户"+re_user_id);
			Log.v("test:", "用戶名="+re_username);
			Log.v("test:", "經度="+re_longitude);
			Log.v("test:", "緯度="+re_latitude);
		} catch (Exception e) {
			Log.v("test:", "false");
			e.printStackTrace();
		}
    }
    /**
     * Background Async Task to Create new product
     * */
    class Up extends AsyncTask<String, String, String> {

        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(LocationAllShow.this);
            pDialog.setMessage("正在上传..");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }
        /**
         * Creating product
         * */
        protected String doInBackground(String... args) {
            	
            String phoneno = getPhoneText.getText().toString();
            String lon = "114.1";
            String lat = "22.6";
            String note = "my home here";
            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("username", phoneno));
            params.add(new BasicNameValuePair("lon", lon));
            params.add(new BasicNameValuePair("lat", lat));
            params.add(new BasicNameValuePair("note", note));

            // getting JSON Object
            // Note that create product url accepts POST method
           try{
        	   JSONObject json = JSONParser.makeHttpRequest(url_up,"POST", params);
	   			
        	    //String re_username = json.getString("username");
	   			//String re_longitude = json.getString("lon");
	   			//String re_latitude = json.getString("lat");
	   			
	   			//Log.v("test:", "用戶名="+re_username);
	   			//Log.v("test:", "經度="+re_longitude);
	   			//Log.v("test:", "緯度="+re_latitude);
	   			
	            //String message = json.getString(TAG_MESSAGE);
        	    String message ="";
	            return message;
           }catch(Exception e){
               e.printStackTrace(); 
               return "";          
           }
            // check for success tag   
        }
          
        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String message) {                    
            pDialog.dismiss();
           //message 为接收doInbackground的返回值
            Toast.makeText(getApplicationContext(), message, 8000).show();    
                
               
        }
    }
    public void getinfo(String url_t){
    	String strUrl1 = url_t;
        //获得返回的Json字符串   
        String strResult1 = connServerForResult(strUrl1); 
        
        Log.v("strResult1",strResult1);
        
        parseJsonMulti(strResult1);
    }
    double lat=0;
    double lon=0;
    private String connServerForResult(String strUrl) {   
        // HttpGet对象   
        HttpGet httpRequest = new HttpGet(strUrl);   
        String strResult = "";   
        try {   
            // HttpClient对象   
            HttpClient httpClient = new DefaultHttpClient();   
            // 获得HttpResponse对象   
            HttpResponse httpResponse = httpClient.execute(httpRequest);   
            if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {   
                // 取得返回的数据   
                strResult = EntityUtils.toString(httpResponse.getEntity());   
            }   
        } catch (ClientProtocolException e) { 
        	
        	Toast.makeText(LocationAllShow.this,
        			"protocol error", Toast.LENGTH_SHORT).show();
          
            e.printStackTrace();   
        } catch (IOException e) {   
        	Toast.makeText(LocationAllShow.this,
        			"IO error", Toast.LENGTH_SHORT).show();
           
            e.printStackTrace();   
        }   
        return strResult;   
    }   
    private void parseJsonMulti(String strResult) {   
        try {   

        	Log.v("strResult11","strResult11="+strResult);
        	
        	 int index=strResult.indexOf("[");
	            if(index>0)
	            	strResult=strResult.substring(index, strResult.length()); 
	            
	            Log.v("strResult22","strResult22="+strResult);
	            
	            JSONArray userLocMapData = new JSONArray(strResult);
	            
	            Log.v("userLocMapDataLength",""+userLocMapData.length());
	            
            for(int i = 0; i < userLocMapData.length() ; i++){///基站信息处理
				///MapData m=new MapData(1, dLat[5], dLong[5], 10, 20, 300, 500, 105, "教1", 1, 1, 4);
            	
            
				JSONObject jsonObject = userLocMapData.getJSONObject(i);
				String re_username = jsonObject.getString("username");
				String re_longitude = jsonObject.getString("lon");
				String re_latitude = jsonObject.getString("lat");
				Log.v("test:", "用戶名="+re_username);
				Log.v("test:", "經度="+re_longitude);
				Log.v("test:", "緯度="+re_latitude);
				//String r_username=jsonObject.getString("username"));	//username
			
                // if(jsonObject.isNull("mac_address")) mac_address="";
				 //String mac_address = jsonObject.getString("mac_address");//wifi的mac地址	
				 
				 //String wifi_name=jsonObject.getString("wifi_name");	//ssid
				
				 
				 if(!jsonObject.isNull("lat")&&!jsonObject.isNull("lon")){
				
				 lat= Double.valueOf(jsonObject.getString("lat"));//纬度
				 
				 lon=Double.valueOf(jsonObject.getString("lon"));//经度
				  
				 }
				 //String location_name=jsonObject.getString("location_name");	//ssid
				
				 //String wifi_adds = jsonObject.getString("wifi_adds");//wifi地址 具体到多少路多少号
				
				 //String area = jsonObject.getString("area");//北京的什么区
			
				 //String location_type = jsonObject.getString("location_type");//地点是个什么类型的，写字楼？？
			
				 //String ap_free = jsonObject.getString("ap_free");//ap是否免费
				
				 //String category = jsonObject.getString("category");//ap是否免费
				 
				 //String password = jsonObject.getString("password");//ap是否免费	
				 
				 //String capabilities = jsonObject.getString("capabilities");//ap是否免费	
				 
				 //String user_score = jsonObject.getString("user_score");//ap是否免费	
				
				 //String NW_score = jsonObject.getString("NW_score");//ap是否免费	
				 
            }   
           // tvJson.setText(s);   
        } catch (JSONException e) {   
            System.out.println("Jsons parse error !");   
            e.printStackTrace();   
        }   
    }   
    @Override
    protected void onPause() {
        mMapView.onPause();
        super.onPause();
    }
    
    @Override
    protected void onResume() {
        mMapView.onResume();
        super.onResume();
    }
    
    @Override
    protected void onSaveInstanceState(Bundle outState) {
    	super.onSaveInstanceState(outState);
    	mMapView.onSaveInstanceState(outState);
    	
    }
    
    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
    	super.onRestoreInstanceState(savedInstanceState);
    	mMapView.onRestoreInstanceState(savedInstanceState);
    }
    
    public void testUpdateClick(){
    	
        //mLocClient.requestLocation();
    	this.initPos();
    	
    	
    }
    private void initMapView() {
        mMapView.setLongClickable(true);
        //mMapController.setMapClickEnable(true);
        //mMapView.setSatellite(false);
    }
   

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

	
	/**
     * 监听函数，又新位置的时候，格式化成字符串，输出到屏幕中
     */
    public class MyLocationListenner implements BDLocationListener {
        @Override
        public void onReceiveLocation(BDLocation location) {
            if (location == null)
                return ;
            
            locData.latitude = location.getLatitude();
            locData.longitude = location.getLongitude();
            locData.direction = 2.0f;
            locData.accuracy = location.getRadius();
            locData.direction = location.getDerect();
            //Log.d("loctest",String.format("before: lat: %f lon: %f", location.getLatitude(),location.getLongitude()));
           
            // GeoPoint p = CoordinateConver.fromGcjToBaidu(new GeoPoint((int)(locData.latitude* 1e6), (int)(locData.longitude *  1e6)));
          //  Log.d("loctest",String.format("before: lat: %d lon: %d", p.getLatitudeE6(),p.getLongitudeE6()));
           
            myLocationOverlay.setData(locData);
            //mMapView.refresh();
            //mMapController.animateTo(new GeoPoint((int)(locData.latitude* 1e6), (int)(locData.longitude *  1e6)), mHandler.obtainMessage(1));
        }
        
        public void onReceivePoi(BDLocation poiLocation) {
            if (poiLocation == null){
                return ;
            }
        }
    }
    
    public class NotifyLister extends BDNotifyListener{
        public void onNotify(BDLocation mlocation, float distance) {
        }
    }
    
}


